<div class="deals form">
	<div class="clear"></div>
	<?php
	$javascript->link('/js/mustache.js',false);
	//$javascript->link('/cms/js/jquery.template.js',false);
	$javascript->link('/cms/js/jquery.qtip.js',false);
	$javascript->link('/cms/js/jquery.ajaxify.js',false);
	
	$dealAssetStatus = DealAsset::PUBLISHED;
	$defaultImage = 1;
	?>
	<?php echo $form->create('Deal',array('url'=>'/'.$this->params['url']['url'],'id'=>'deal_form','enctype'=>'multipart/form-data'));?>
	<?php $form->defaultEmpty = __("-Select-"); ?>
	<fieldset>
		<?php
		echo $form->inputs(array('fieldset'=>false),null,"add");
		
		echo $form->input('DealAsset.0.name',array('type'=>'file','label'=>__('Upload Image'),'class'=>'required'));
		echo $form->input('DealAsset.0.status',array('type'=>'hidden','value'=>$dealAssetStatus,'class'=>'required'));
		echo $form->input('DealAsset.0.is_default',array('type'=>'hidden','value'=>$defaultImage,'class'=>'required'));
		?>
		<div id='place_holder'></div>
		<?php echo $html->link(__('Add more image'),'#',array('onclick'=>'return add_upload_field()')); ?>
	</fieldset>
	<?php echo $form->end(__('Submit'));?>
</div>
<script type='text/javascript'>
var yearRange = "<?php echo date("Y").":".(date("Y") + 30); ?>";
$(document).ready(function(){
	$( "#DealExpires" ).datepicker( "option", "yearRange", yearRange );
	$( "#DealExpires" ).datepicker( "option", "minDate", 0 );

	$( "#DealPublishOnDate" ).datepicker( "option", "yearRange", yearRange );
	$( "#DealPublishOnDate" ).datepicker( "option", "minDate", 0 );
})
var tmpObj = new templateClass(1);
var dealStatus = <?php echo $dealAssetStatus ?>;
var defaultTemplate = '<input type="file" id="DealAsset{{i}}Name" value="" name="data[DealAsset][{{i}}][name]"><input type="hidden" id="DealAsset{{i}}Status" value='+dealStatus+' name="data[DealAsset][{{i}}][status]">';
//var tmpToAppend = $.template(defaultTemplate);

function templateClass(count)
{
	this.count = count;
}
	
function add_upload_field()
{
	//$('#place_holder').append(tmpToAppend,{'i':tmpObj.count});
	var tmpToAppend = Mustache.to_html(defaultTemplate,{'i':tmpObj.count});
	$('#place_holder').append(tmpToAppend);
	tmpObj.count ++;
	return false;
}
</script>